from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-11 14:14:24.068151
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 11, Oct, 2022
Time: 14:14:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6733
Nobs: 806.000 HQIC: -50.9961
Log likelihood: 10429.5 FPE: 5.82529e-23
AIC: -51.1973 Det(Omega_mle): 5.21341e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296916 0.052713 5.633 0.000
L1.Burgenland 0.109246 0.035451 3.082 0.002
L1.Kärnten -0.106408 0.018876 -5.637 0.000
L1.Niederösterreich 0.210146 0.074142 2.834 0.005
L1.Oberösterreich 0.100052 0.071121 1.407 0.159
L1.Salzburg 0.251537 0.037796 6.655 0.000
L1.Steiermark 0.038236 0.049454 0.773 0.439
L1.Tirol 0.106275 0.040105 2.650 0.008
L1.Vorarlberg -0.059166 0.034473 -1.716 0.086
L1.Wien 0.057702 0.063525 0.908 0.364
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064224 0.109137 0.588 0.556
L1.Burgenland -0.033598 0.073398 -0.458 0.647
L1.Kärnten 0.047830 0.039081 1.224 0.221
L1.Niederösterreich -0.172451 0.153503 -1.123 0.261
L1.Oberösterreich 0.385381 0.147249 2.617 0.009
L1.Salzburg 0.287084 0.078252 3.669 0.000
L1.Steiermark 0.106026 0.102389 1.036 0.300
L1.Tirol 0.313449 0.083033 3.775 0.000
L1.Vorarlberg 0.025294 0.071373 0.354 0.723
L1.Wien -0.016592 0.131522 -0.126 0.900
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189818 0.027064 7.014 0.000
L1.Burgenland 0.090176 0.018201 4.954 0.000
L1.Kärnten -0.008437 0.009691 -0.871 0.384
L1.Niederösterreich 0.264484 0.038065 6.948 0.000
L1.Oberösterreich 0.126304 0.036515 3.459 0.001
L1.Salzburg 0.047547 0.019405 2.450 0.014
L1.Steiermark 0.017069 0.025390 0.672 0.501
L1.Tirol 0.094289 0.020590 4.579 0.000
L1.Vorarlberg 0.059330 0.017699 3.352 0.001
L1.Wien 0.120461 0.032615 3.693 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110041 0.027734 3.968 0.000
L1.Burgenland 0.044253 0.018652 2.373 0.018
L1.Kärnten -0.016096 0.009931 -1.621 0.105
L1.Niederösterreich 0.192974 0.039008 4.947 0.000
L1.Oberösterreich 0.294216 0.037419 7.863 0.000
L1.Salzburg 0.115123 0.019885 5.789 0.000
L1.Steiermark 0.099842 0.026019 3.837 0.000
L1.Tirol 0.116301 0.021100 5.512 0.000
L1.Vorarlberg 0.070637 0.018137 3.895 0.000
L1.Wien -0.027676 0.033422 -0.828 0.408
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128873 0.050295 2.562 0.010
L1.Burgenland -0.051125 0.033825 -1.511 0.131
L1.Kärnten -0.040282 0.018011 -2.237 0.025
L1.Niederösterreich 0.170411 0.070742 2.409 0.016
L1.Oberösterreich 0.137730 0.067859 2.030 0.042
L1.Salzburg 0.285423 0.036062 7.915 0.000
L1.Steiermark 0.034790 0.047186 0.737 0.461
L1.Tirol 0.164144 0.038266 4.290 0.000
L1.Vorarlberg 0.103860 0.032892 3.158 0.002
L1.Wien 0.068468 0.060612 1.130 0.259
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060011 0.039874 1.505 0.132
L1.Burgenland 0.038484 0.026817 1.435 0.151
L1.Kärnten 0.050656 0.014279 3.548 0.000
L1.Niederösterreich 0.225684 0.056084 4.024 0.000
L1.Oberösterreich 0.282238 0.053799 5.246 0.000
L1.Salzburg 0.050885 0.028590 1.780 0.075
L1.Steiermark -0.007122 0.037409 -0.190 0.849
L1.Tirol 0.149862 0.030337 4.940 0.000
L1.Vorarlberg 0.071001 0.026077 2.723 0.006
L1.Wien 0.079220 0.048053 1.649 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178547 0.047663 3.746 0.000
L1.Burgenland -0.005882 0.032055 -0.183 0.854
L1.Kärnten -0.061082 0.017068 -3.579 0.000
L1.Niederösterreich -0.083670 0.067039 -1.248 0.212
L1.Oberösterreich 0.192470 0.064307 2.993 0.003
L1.Salzburg 0.056819 0.034175 1.663 0.096
L1.Steiermark 0.231035 0.044716 5.167 0.000
L1.Tirol 0.493701 0.036263 13.615 0.000
L1.Vorarlberg 0.049469 0.031170 1.587 0.113
L1.Wien -0.049092 0.057439 -0.855 0.393
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162185 0.054725 2.964 0.003
L1.Burgenland -0.011445 0.036804 -0.311 0.756
L1.Kärnten 0.065973 0.019597 3.367 0.001
L1.Niederösterreich 0.200515 0.076972 2.605 0.009
L1.Oberösterreich -0.061050 0.073836 -0.827 0.408
L1.Salzburg 0.216138 0.039239 5.508 0.000
L1.Steiermark 0.113807 0.051342 2.217 0.027
L1.Tirol 0.076878 0.041636 1.846 0.065
L1.Vorarlberg 0.124490 0.035789 3.478 0.001
L1.Wien 0.114603 0.065950 1.738 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353815 0.031869 11.102 0.000
L1.Burgenland 0.006076 0.021433 0.283 0.777
L1.Kärnten -0.023547 0.011412 -2.063 0.039
L1.Niederösterreich 0.223789 0.044825 4.993 0.000
L1.Oberösterreich 0.175056 0.042998 4.071 0.000
L1.Salzburg 0.047209 0.022851 2.066 0.039
L1.Steiermark -0.016935 0.029899 -0.566 0.571
L1.Tirol 0.108662 0.024247 4.482 0.000
L1.Vorarlberg 0.073525 0.020842 3.528 0.000
L1.Wien 0.053626 0.038406 1.396 0.163
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041146 0.152772 0.190302 0.157144 0.125121 0.113837 0.065658 0.226882
Kärnten 0.041146 1.000000 -0.002552 0.129704 0.041447 0.096097 0.429571 -0.053129 0.101209
Niederösterreich 0.152772 -0.002552 1.000000 0.336932 0.154894 0.300655 0.111329 0.183821 0.328060
Oberösterreich 0.190302 0.129704 0.336932 1.000000 0.232177 0.332745 0.172541 0.172524 0.263106
Salzburg 0.157144 0.041447 0.154894 0.232177 1.000000 0.146494 0.126623 0.148819 0.134913
Steiermark 0.125121 0.096097 0.300655 0.332745 0.146494 1.000000 0.153659 0.141123 0.080235
Tirol 0.113837 0.429571 0.111329 0.172541 0.126623 0.153659 1.000000 0.114891 0.155663
Vorarlberg 0.065658 -0.053129 0.183821 0.172524 0.148819 0.141123 0.114891 1.000000 0.007349
Wien 0.226882 0.101209 0.328060 0.263106 0.134913 0.080235 0.155663 0.007349 1.000000